﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace Plot.Primitives
{
    internal class XYDataShape : PShape
    {
        private List<Point> points;

        public XYDataShape(double x, double y, double[][] points) : base(x, y, 0d)
        {
            this.points = new List<Point>(new[]{StartPoint});
            foreach (var point in points)
                this.points.Add(new Point(point[0] + StartPoint.X, StartPoint.Y - point[1]));

            if (this.points.Count < 2)
                throw new InvalidOperationException("Требуется как минимум 2 точки для постороения графика");
        }

        public override IEnumerator<PShape> GetEnumerator()
        {
            return Enumerable.Range(1, points.Count - 1).
                Select(i => new PLine(points[i - 1].X, points[i - 1].Y, points[i].X, points[i].Y)).
                GetEnumerator();
        }
    }
}